﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using XT.Model;

namespace XT.Repository
{
    public interface IRepository<U, V> where U : class, IEntity<V>
    {
        bool Compare<V>(V x, V y) where V : class, IEntity;
        U Find(V id);
        T ExecuteQuery<T>(Func<DataContext, T> pred);
        T ExecuteQuery<T>(Func<DataContext, T> pred, DataContext ctx);
        IEnumerable<T> FindAll<T>(OrderByDelegate<T> orderBy) where T : class, IEntity;
        IEnumerable<T> FindAll<T>(OrderByDelegate<T> orderBy, int pageIndex, int pageSize) where T : class, IEntity;
        IEnumerable<T> FindAllByCriteria<T>(Expression<Func<T, bool>> exp, OrderByDelegate<T> orderBy) where T : class, IEntity;
        IEnumerable<T> FindAllByCriteria<T>(Expression<Func<T, bool>> exp, OrderByDelegate<T> orderBy, int pageIndex, int pageSize) where T : class, IEntity;
        Account checkLogin(string mail, string password);
        void Add(U u);
        U Save(V id, Func<DataContext, U, bool> pred);
    }

    public delegate IQueryable<T> OrderByDelegate<T>(IQueryable<T> q);
}
